package com.pudu.mydemo.act;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.pudu.mydemo.view.CircleSeekBar;
import com.pudutech.pdrobot.R;


/**
 * Created by guiliu on 2016/7/12.
 */
public class GoBackActivity extends BaseHomeActivity {
    private CircleSeekBar circularSeekbar;
    private ImageView center_image,route_select;
    private TextView instance;
    RelativeLayout center_instance;
    private ImageView cancel, ok;
    private boolean isMove;
    private int currentInstance = 0;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.goback;
    }

    @Override
    public void initData() {
        super.initData();

    }

    @Override
    public void initView() {
//        circularSeekbar = (CircularSeekBar)findViewById(R.id.daoshu);
        circularSeekbar = (CircleSeekBar)findViewById(R.id.daoshu);
        center_image=(ImageView)findViewById(R.id.center_image);
        center_instance=(RelativeLayout)findViewById(R.id.center_instance);
        instance=(TextView)findViewById(R.id.instance);
        cancel = (ImageView)findViewById(R.id.cancel);
        ok=(ImageView)findViewById(R.id.ok);
        route_select = (ImageView)findViewById(R.id.route_select);
        circularSeekbar.setProgress(0);
        circularSeekbar.setProgressFrontColor(Color.WHITE);

        center_image.setVisibility(View.VISIBLE);
        center_instance.setVisibility(View.GONE);
        circularSeekbar.setSeekBarChangeListener(new CircleSeekBar.OnSeekChangeListener() {
            @Override
            public void onProgressChange(CircleSeekBar view, int newProgress) {
                Log.d("Welcome", "Progress:" + view.getProgress());
                if(!isMove){
                    isMove = true;

                    center_image.setVisibility(View.GONE);
                    center_instance.setVisibility(View.VISIBLE);
                }else {
                    route_select.setVisibility(View.GONE);
                    currentInstance = newProgress/10;
                    if(currentInstance == 10) {
                        instance.setText(""+currentInstance);
                    } else{
                        instance.setText("0"+currentInstance);
                    }

                }
            }
        });

    }

    @Override
    public void initEvent() {
       cancel.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               finish();
           }
       });

        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction("Intent_Action_Move");
                intent.putExtra("action","ACTION_GOBACK_MOVE");
                if( 0 == Integer.parseInt(instance.getText().toString())) {
                    Toast.makeText(GoBackActivity.this,"移动距离为0，请重新选择",Toast.LENGTH_LONG).show();
                } else {
                    intent.putExtra("data",instance.getText().toString());
                    startActivity(intent);
                    finish();
                }

            }
        });



    }

    public static int px2dip(Context context, float pxValue){
    final float scale = context.getResources().getDisplayMetrics().density;
        Log.e("goback","scale:"+scale);
    return (int)(pxValue / scale +0.5f);
    }
}
